require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsHeroSkillHandler ={};
local this = RedDotsHeroSkillHandler;

local rankConfig = nil;

function RedDotsHeroSkillHandler.init()
    CloseEvent(Config.EventType.Fresh_HeroSkill,this.update);

    ListenEvent(Config.EventType.Fresh_HeroSkill,this.update);

    if rankConfig==nil then
        rankConfig =G.dataTable["t_herorank"];
    end

    return this;
end

--参数1：指定英雄Id，nil代表检查所有英雄
---英雄详情技能页签红点
function RedDotsHeroSkillHandler.getFlag(...)
    local flag = Config.RedDotsFlagState.None;
    local partnerId = ...;
    local heroList = nil;
    if partnerId~=nil then
        heroList ={};
        local hero = logicMgr.HeroManager.getHeroDatabyPartnerId(partnerId,true);
        if hero~=nil then
            table.insert(heroList,hero);
        end
    else
        heroList = logicMgr.HeroManager.GetAllHero(true);
    end
    for i = 1, #heroList do
        flag = this.getFlagByHero(heroList[i]);
        if flag == Config.RedDotsFlagState.Needful then
            break;
        end
    end
    return flag;
end

function RedDotsHeroSkillHandler.getFlagByHero(hero)
    local flag = Config.RedDotsFlagState.None;
    local key = logicMgr.HeroManager.GetRoleInfo().playerId..Config.EventType.Fresh_HeroSkill..hero.partnerModelId;
    local xx = Util.GetPlayerPrefs(key);
    if Util.GetPlayerPrefs(key) == "1" then
        flag = Config.RedDotsFlagState.Needful;
    end
    return flag;
end

function RedDotsHeroSkillHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.HeroSkill);
end